#pragma once
#include "vn/Math.hpp"
#include "vn/Console.h"

#define ASSERT_FLOAT_EQUAL(a, b) assert(Math::Abs(b - a) < 0.00000000001);

void MathTest() {_test_func_;

	// Math::Round(123.45678, 2) co van de

	ASSERT_FLOAT_EQUAL(	Math::Abs(-1.5)		, 1.5 );
	ASSERT_FLOAT_EQUAL(	Math::Ceiling(1.5)	, 2.0 );
	ASSERT_FLOAT_EQUAL(	Math::Floor(1.5)	, 1.0 );

	ASSERT_FLOAT_EQUAL(	Math::Round(1.4)	, 1.0 );
	ASSERT_FLOAT_EQUAL(	Math::Round(1.6)	, 2.0 );
	ASSERT_FLOAT_EQUAL(	Math::Round(-1.4)	, -1.0 );
	ASSERT_FLOAT_EQUAL(	Math::Round(-1.6)	, -2.0 );

	ASSERT_FLOAT_EQUAL(	Math::Round(123.456789, 0)	, 123 );
	//for mingw, round(123.456789) == 123.45999999999999 => add ASSERT_FLOAT_QEUAL
	ASSERT_FLOAT_EQUAL(	Math::Round(123.456789, 1)	, 123.5 );
	ASSERT_FLOAT_EQUAL(	Math::Round(123.456789, 2)	, 123.46 );
	ASSERT_FLOAT_EQUAL(	Math::Round(123.456789, 3)	, 123.457 );

	ASSERT_FLOAT_EQUAL(	Math::Truncate(1.6)		, 1.0 );
	ASSERT_FLOAT_EQUAL(	Math::Truncate(1.4)		, 1.0 );
	ASSERT_FLOAT_EQUAL(	Math::Truncate(-1.4)	, -1.0 );
	ASSERT_FLOAT_EQUAL(	Math::Truncate(-1.6)	, -1.0 );

	ASSERT_FLOAT_EQUAL(	Math::Min(1,	2)	, 1 );
	ASSERT_FLOAT_EQUAL(	Math::Min(2.0,	1)	, 1 );

	ASSERT_FLOAT_EQUAL(	Math::Max(1,	2)	, 2 );
	ASSERT_FLOAT_EQUAL(	Math::Max(2.0,	1.0), 2 );

	ASSERT_FLOAT_EQUAL(	Math::Acos(0.0)	, Math::PI_2);
	ASSERT_FLOAT_EQUAL(	Math::Asin(0.0)	, 0);
	ASSERT_FLOAT_EQUAL(	Math::Atan(0.0)	, 0.0);
	ASSERT_FLOAT_EQUAL(	Math::Round(Math::Atan2(1.0, 1.0), 5)
		, Math::Round(Math::PI_4, 5) );

	ASSERT_FLOAT_EQUAL(	Math::Cos(0.0) ,  1.0);
	ASSERT_FLOAT_EQUAL(	Math::Sin(0.0) ,  0.0);
	ASSERT_FLOAT_EQUAL(	Math::Tan(0.0) ,  0.0);

	ASSERT_FLOAT_EQUAL(	Math::Cosh(0.0) , 1.0 );
	ASSERT_FLOAT_EQUAL(	Math::Sinh(0.0) , 0.0 );
	ASSERT_FLOAT_EQUAL(	Math::Tanh(0.0) , 0.0 );

	ASSERT_FLOAT_EQUAL(	Math::Pow(2.0, 3.0) , 8.0);
	ASSERT_FLOAT_EQUAL(	Math::Sqrt(81.0) , 9.0);
	ASSERT_FLOAT_EQUAL(	Math::Exp(1.0) , Math::E );			// exp(1) made error, you must write exp(1.0)
	ASSERT_FLOAT_EQUAL(	Math::Log(Math::Exp(2.0)) , 2.0 );
	ASSERT_FLOAT_EQUAL(	Math::Log10(10.0) , 1);
	ASSERT_FLOAT_EQUAL(	Math::Log(8.0, 2.0) , 3);


	int n;
	double r;
	double y;

	y = Math::Frexp(16.400000, &n);
	assert(	y == 0.512500 && n == 5 );

	y = Math::Modf( -14.87654321, &r );
	ASSERT_FLOAT_EQUAL(	Math::Round(y, 6) , -0.876543)
	ASSERT_FLOAT_EQUAL( r , -14 );

	assert( Math::IEEERemainder(-10.0, -3.0) == -1 );
	assert( Math::Ldexp(4.0, 3) == 32.0 );
}

